/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package attackDetection;
import Storage.DBConnect;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.ResultSet;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
/**
 *
 * @author john
 */
public class AttackDetection {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        DBConnect db = new DBConnect();
        
        // Internal Variable
        ResultSet result;
        Plog example = new Plog();
        Tracer test = new Tracer();
        Nstat cnstat = new Nstat();
        cnstat.loadhoptime();
        cnstat.calHopParameter();
        int rowCount = 0;
        int currentRow = 0;
        
        // Suspicious Output
        int i = 0;
        HashMap<Integer,Integer> numOfDelays = new HashMap<Integer,Integer>();
        int numOfDelayThresh = 0;
        Suspicious output;
        
        db.executeQuery("SELECT * FROM log WHERE pseqno=1", true);
        result = db.getResultSet();
        
        if(result==null)
            System.out.println("NULL");
        
        try
        {
            currentRow = result.getRow();
            result.last();
            rowCount = result.getRow();
            System.out.println(rowCount);
            result.absolute(currentRow);

//            while(result.next()){
//                example.Init(result);
//                test.callList(example);
//                test.replayCheck(cnstat.getMeanhoptime()+(2*cnstat.getSdhoptime()), numOfDelays);
//                test.clear();
//            }
            
        } catch (Exception e){
            System.out.println("Exception: " + e.getLocalizedMessage());
        }
        
            for(Iterator it = numOfDelays.keySet().iterator(); it.hasNext();) {
                Integer key = (Integer) it.next();
                Integer value = (Integer) numOfDelays.get(key);
                System.out.println(key + " = " + value);
            }
        
        
    }
    
    public boolean replayCheckLocal(Date subject){
        Date currentTime = new Date();
        double lb = 0;
        double ub = 180;
        double diff;
        
        diff=currentTime.getTime() - subject.getTime();
        if (diff < lb || diff > ub){
            return true;
        }
        else
            return true;
    }
    
    public boolean replatCheckGlobal(Plog p){
        double lb = 0;
        double ub = 15 * p.getHc();
        double diff;
        
        diff = p.getTimeStamp().getTime() - p.getTimeso().getTime();
        
        if(diff < lb || diff > ub){
            return true;
        }
        else       
            return false;
    }
}
